<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/25 0025
 * Time: 10:30
 */

namespace app\manager\controller;

use app\common\controller\Base as CommonBase;
use member\captain\admin;
use member\permission\admin as p_admin;
use classes\Node;

class Base extends CommonBase
{
    function _initialize()
    {
        parent::_initialize();
        $this->gateway();
    }

    private function gateway()
    {
        $this->permission();
    }

    // 权限相关
    private function permission()
    {
        if (!admin::check()) { // 若非管理员, 则若访问的非公共控制器, 则跳转到登录页面
            if (strtolower(request()->controller()) !== 'common') {
                $this->redirect(url('manager/common/login'));
            }
        } else { // 若为管理员, 则进行节点权限验证
//            Node::generate();
            $admin = admin::info();
            $handle_permission = new p_admin($admin);
            if (!$handle_permission->validate()) {
                $this->redirect(url('manager/common/forbid'));
            }
        }
    }
}